package com.ehotting.edsta.csharpServer.utils;


import org.springframework.data.redis.core.ValueOperations;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

public class AbstractMessageMap<K, V> {
    @Resource(
            name = "redisTemplate"
    )
    private ValueOperations<K, V> lop;

    public AbstractMessageMap() {
    }

    public void set(K k, V t) {
        this.lop.set(k, t);
    }

    public void set(K k, V t, long time) {
        this.lop.set(k, t, time, TimeUnit.SECONDS);
    }

    public V get(K k) {
        return this.lop.get(k);
    }

    public V getAndRemove(K k) {
        V v = this.lop.getAndSet(k, null);
        return v;
    }

    public Long size(K k) {
        return this.lop.size(k);
    }
}
